{include file='public:header-css'/}
<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        {include file='public:left-menu'/}
        <!--End 左侧导航-->
        <!--头部信息-->
        {include file='public:nav-header' title="店铺管理" subTitle="店铺设置"/}
        <!--End 头部信息-->

        <!--页面主要内容-->
        <main class="lyear-layout-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header form-header"><h4>店铺设置</h4></div>
                            <div class="card-body">
                                <form method="post" id="submit-form" class="">
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <label class="form-title">会员账号</label>
                                            <input type="text" class="form-control" value="{$store.user.mobile}" readonly/>
                                        </div>
                                        <div class="col-md-6">
                                            <label class="form-title">店铺名称</label>
                                            <input type="text" class="form-control" name="store_name" value="{$store.store_name}"/>
                                            <span class="error" id="err_store_name"></span>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-6">
                                            <label class="form-title">联系人</label>
                                            <input type="text" class="form-control" name="contacts_name" value="{$store.contacts_name}"/>
                                            <span class="error" id="err_contacts_name"></span>
                                        </div>
                                        <div class="col-md-6">
                                            <label class="form-title">联系电话</label>
                                            <input type="text" class="form-control" name="contacts_mobile" value="{$store.contacts_mobile}"/>
                                            <span class="error" id="err_contacts_mobile"></span>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-3">
                                            <label class="form-title">所在地区</label>
                                            <div class="form-inline">
                                                <input type="text" class="form-control" name="province" value="{$store.province}" readonly/>
                                                <input type="text" class="form-control" name="city" value="{$store.city}" readonly/>
                                                <input type="text" class="form-control" name="district" value="{$store.district}" readonly/>
                                            </div>
                                            <span class="error" id="err_district"></span>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">详细地址</label>
                                            <input type="text" class="form-control" name="store_address" value="{$store.store_address}"/>
                                            <span class="error" id="err_store_address"></span>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">经度</label>
                                            <input type="text" class="form-control" name="longitude" readonly value="{$store.longitude}"/>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">纬度</label>
                                            <input type="text" class="form-control" name="latitude" readonly value="{$store.latitude}"/>
                                        </div>
                                    </div>
                                    <div class="form-group col-md-12">
                                        <div class="row">
                                            <label class="form-title">搜索地区</label>
                                            <div class="input-group">
                                                <input type="text" id="search_input" class="form-control" placeholder="请输入地址搜索">
                                                <span class="input-group-btn">
                                                     <button class="btn btn-default" id="confirm" type="button">确定</button>
                                                </span>
                                            </div>
                                            <div class="map">
                                                <div id="map"></div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="form-group row">
                                        <div class="col-md-3">
                                            <label class="form-title">身份证正面</label>
                                            <div class="upload-row img">
                                                <img class="upload-img" id="store_person_cert" src="{$store.store_person_cert|default='__STATIC__/images/upload.png'}">
                                                <input type="hidden" name="store_person_cert" value="{$store.store_person_cert}">
                                                <div class="input-group-btn">
                                                    <button onclick="GetUploadify(1,'store_person_cert','cert','call_back')" class="btn btn-default" type="button">上传图片</button>
                                                </div>
                                            </div>
                                            <span class="error" id="err_store_person_cert"></span>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">身份证反面</label>
                                            <div class="upload-row img">
                                                <img class="upload-img" id="store_person_cert1" src="{$store.store_person_cert1|default='__STATIC__/images/upload.png'}">
                                                <input type="hidden" name="store_person_cert1" value="{$store.store_person_cert1}">
                                                <div class="input-group-btn">
                                                    <button onclick="GetUploadify(1,'store_person_cert1','cert','call_back')" class="btn btn-default" type="button">上传图片</button>
                                                </div>
                                            </div>
                                            <span class="error" id="err_store_person_cert1"></span>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">门头照片</label>
                                            <div class="upload-row img">
                                                <img class="upload-img" id="store_logo" src="{$store.store_logo|default='__STATIC__/images/upload.png'}">
                                                <input type="hidden" name="store_logo" value="{$store.store_logo}">
                                                <div class="input-group-btn">
                                                    <button onclick="GetUploadify(1,'store_logo','store_logo','call_back')" class="btn btn-default" type="button">上传图片</button>
                                                </div>
                                            </div>
                                            <span class="error" id="err_store_logo"></span>
                                        </div>
                                        <div class="col-md-3">
                                            <label class="form-title">营业执照</label>
                                            <div class="upload-row img">
                                                <img class="upload-img" id="business_licence_cert" src="{$store.business_licence_cert|default='__STATIC__/images/upload.png'}">
                                                <input type="hidden" name="business_licence_cert" value="{$store.business_licence_cert}">
                                                <div class="input-group-btn">
                                                    <button onclick="GetUploadify(1,'business_licence_cert','cert','call_back')" class="btn btn-default" type="button">上传图片</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-md-12">
                                            <input type="hidden" name="{$store.pk}" value="{$store[$store.pk]}">
                                            <button type="button" class="btn-theme submit-btn">确定</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<style>
    .form-inline{
        justify-content: space-between;
    }
    .form-inline .form-control,.form-inline select{
        width: 33%;
    }
    .map{
        height: 400px;
        margin-top: 10px;
    }
    #map{
        height: 400px;
    }
    #map img{
        max-width: none!important;
    }
    .BMap_cpyCtrl{
        display: none;
    }
    .anchorBL{
        bottom: 5px!important;
    }
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=3.0&ak=I2aY4C7aehpX6gi8tjTuMFzZp0SLdS6g"></script>
<script type="text/javascript">
    var lng,lat,province,city,district,address;
    var myValue;
    var loadCount = 0;
    var map = new BMap.Map("map");
    $(document).ready(function () {
        layer.photos({
            photos: '.img'
            ,anim: 5
        });
        initMap();
    });
    function initMap(){
        var city1 = '{$store.city}' || '菏泽';
        //115.51227,35.239408 菏泽火车站
        var longitude=$('[name=longitude]').val() || '115.51227';
        var latitude=$('[name=latitude]').val() || '35.239408';
        // 百度地图API功能
        // map =  new BMap.Map("map");   // 创建Map实例
        var new_point = new BMap.Point(longitude,latitude);
        map.centerAndZoom(new_point, 14);  // 初始化地图,设置中心点坐标和地图级别
        //添加地图类型控件
        map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}));
        var marker = new BMap.Marker(new_point);  // 创建标注
        map.panTo(new_point);
        map.addOverlay(marker);
        map.setCurrentCity(city1);          // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
        map.enableInertialDragging();
        map.enableContinuousZoom();
        map.addEventListener("tilesloaded",function(){
            if(loadCount == 1){
                map.setCenter(new_point);
            }
            loadCount = loadCount + 1;
        });
        var ac = new BMap.Autocomplete(    //建立一个自动完成的对象
            {"input" : "search_input"
                ,"location" : map
            });
        // ac.setInputValue(all_address);
        ac.addEventListener("onhighlight", function(e) {  //鼠标放在下拉列表上的事件
            var str = "";
            var _value = e.fromitem.value;
            var value = "";
            if (e.fromitem.index > -1) {
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str = "FromItem<br />index = " + e.fromitem.index + "<br />value = " + value;

            value = "";
            if (e.toitem.index > -1) {
                _value = e.toitem.value;
                value = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            }
            str += "<br />ToItem<br />index = " + e.toitem.index + "<br />value = " + value;
            // G("searchResultPanel").innerHTML = str;
        });
        ac.addEventListener("onconfirm", function(e) {    //鼠标点击下拉列表后的事件
            var _value = e.item.value;
            city=_value.city;
            district=_value.district;
            myValue = _value.province +  _value.city +  _value.district +  _value.street +  _value.business;
            setPlace();
        });
    }
    function setPlace(){
        map.clearOverlays();    //清除地图上所有覆盖物
        function myFun(){
            var title=local.getResults().getPoi(0).title;
            var pp = local.getResults().getPoi(0).point;    //获取第一个智能搜索的结果
            map.centerAndZoom(pp, 18);
            map.addOverlay(new BMap.Marker(pp));    //添加标注
            province=local.getResults().getPoi(0).province;
            lng=pp.lng;
            lat=pp.lat;
            address=title;
        }
        var local = new BMap.LocalSearch(map, { //智能搜索
            onSearchComplete: myFun
        });
        local.search(myValue);
    }
    function G(id) {
        return document.getElementById(id);
    }
    $(function () {
        $('#confirm').on('click',function () {
            var search_input_val=$('#search_input').val();
            if (search_input_val==''){
                showErrorMsg('请输入地址搜索');
                return;
            }
            $('[name=province]').val(province);
            $('[name=city]').val(city);
            $('[name=district]').val(district);
            $('[name=store_address]').val(address);
            $('[name=longitude]').val(lng);
            $('[name=latitude]').val(lat);
        });
        $('.submit-btn').click(function () {
            $('span.error').hide();
            $('.has-error').removeClass('has-error');
            var url = "{:url('Store/setting')}";
            var data = $('#submit-form').serialize();
            public_ajax(url,data,function (data) {
                if (data.code == 1) {
                    showSuccessMsg(data.msg, function () {
                        if (data.data.url) {
                            location.href = data.data.url;
                        }
                    });
                } else if (data.code == 10) {
                    showErrorMsg(data.msg);
                    $.each(data.result, function(index, item) {
                        $('#err_' + index).text(item).show();
                        $('#err_' + index).parent().addClass('has-error');
                    });
                } else {
                    showErrorMsg(data.msg);
                }
            });
        });
    });
    function call_back(fileurl_tmp,fileurl_id)
    {
        $("[name="+fileurl_id+"]").val(fileurl_tmp);
        $("#"+fileurl_id).attr('src', fileurl_tmp);
    }
</script>
</body>
</html>
